import {
  reqGetDataListByParentId,
  reqQueryDictIdByName,
} from '@/views/Custom/SystemSettingsMng/DictMng/api/DictMngApi';
const actions = {
  // 薪水
  async getSalaryListByParentId({ commit }, params) {
    let result = await reqGetDataListByParentId(params);
    commit('GETSALARYLISTBYPARENTID', result.data.dictDataList);
  },
  // 学历
  async getEduListByParentId({ commit }, params) {
    let result = await reqGetDataListByParentId(params);
    commit('GETEDULISTBYPARENTID', result.data.dictDataList);
  },
  // 工作经验
  async getExperienceListByParentId({ commit }, params) {
    let result = await reqGetDataListByParentId(params);
    commit('GETEXPERIENCELISTBYPARENTID', result.data.dictDataList);
  },
  // 根据parentId 获取对应子集
  async getDictIdByName({ commit }, params) {
    let result = await reqQueryDictIdByName(params);
    commit('GETDICTIDBYNAME', result.data.dict);
    return result.data.dict || {};
  },
};
const mutations = {
  //  学历
  GETEDULISTBYPARENTID(state, result) {
    state.educationList = result;
  },
  // 工作经验
  GETEXPERIENCELISTBYPARENTID(state, result) {
    state.experienceList = result;
  },
  // 根据parentId 获取对应子集
  GETDICTIDBYNAME(state, result) {
    state.dictByName = result;
  },
  // 薪水
  GETSALARYLISTBYPARENTID(state, result) {
    state.salaryList = result;
  },
};
const state = {
  // 学历集合
  educationList: [],
  experienceList: [],
  dictByName: {}, // 根据名称查询出来的对象
  salaryList: [],
};
const getters = {
  educationList(state) {
    return state.educationList || [];
  },
  dictId(state) {
    return state.dictByName.id || 0;
  },
  experienceList(state) {
    return state.experienceList || [];
  },
  salaryList(state) {
    return state.salaryList || [];
  },
};
export default {
  namespaced: true,
  actions,
  mutations,
  state,
  getters,
};
